package com.haoshuang.zhouzhoubang.ui.activity

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.haoshuang.zhouzhoubang.config.URLConstants
import com.haoshuang.zhouzhoubang.databinding.ActivityTeamBzBinding
import com.haoshuang.zhouzhoubang.model.bean.BzjData
import com.haoshuang.zhouzhoubang.ui.adapter.BondTd2Adapter
import com.haoshuang.zhouzhoubang.ui.adapter.BondTdAdapter
import com.haoshuang.zhouzhoubang.ui.page.help.detail.HelpDetailActivity
import com.haoshuang.zhouzhoubang.ui.vm.TeamBzViewModel
import com.mufeng.libs.base.BaseActivity
import com.mufeng.libs.base.BaseVMActivity
import com.mufeng.libs.state.observeState
import com.mufeng.libs.utils.startPage
import com.mufeng.libs.utils.toast
import com.mufeng.libs.utils.view.click
import com.mufeng.libs.utils.view.clickWithTrigger


/**
 *  门店保证金
 */
class TeamBzActivity : BaseVMActivity<TeamBzViewModel, ActivityTeamBzBinding>() {

    override fun initView(savedInstanceState: Bundle?) {
        binding.appBar.ivBack.click { finish() }
        binding.appBar.tvTitle.text = "门店保证金"
    }

    var list = arrayListOf<BzjData.PayCategory>()
    var list2 = arrayListOf<BzjData.PayCategory>()
    lateinit var adapter: BondTdAdapter
    lateinit var adapter2: BondTd2Adapter
    override fun initData() {
        vm.getData1()

        binding.apply {
            adapter = BondTdAdapter(list)
            adapter2 = BondTd2Adapter(list2)
            rvList.layoutManager = LinearLayoutManager(this@TeamBzActivity)
            rvList2.layoutManager = LinearLayoutManager(this@TeamBzActivity)
            rvList.adapter = adapter
            rvList2.adapter = adapter2
            adapter2.setOnItemClickListener  { adapter, view, position ->
                startPage<BondTdNewActivity>("bean" to list2[position])
            }
            tvNext.clickWithTrigger {
                if (list.size>0){
                    startPage<BondTd2NewActivity>()
                }

            }

            tvInfo.clickWithTrigger {
                // 保证金规则
                val url="${URLConstants.baseUrl}/index/index/agreement?id=18"
                startPage<HelpDetailActivity>("title" to "保证金规则","url" to url)
            }
        }

    }
        var  deposit_money=""
    override fun onRestart() {
        super.onRestart()
        vm.getData1()
    }
    override fun startObserve() {

        vm.getData1.observeState(this) {
            onLoading { showLoading() }
            onError { code, msg ->
                dismissLoading()
                toast(msg)
            }
            onSuccess {
                dismissLoading()
                if (it != null) {
                    list.clear()
                    list.addAll(it.pay_category)
                    adapter.notifyDataSetChanged()
                    list2.clear()
                    list2.addAll(it.not_pay_category)
                    adapter2.notifyDataSetChanged()
                    deposit_money=it.deposit_money
                }
            }
        }
    }

}